import log from '@dfeidao/atom-nodejs/logger/log';
import count from '@dfeidao/atom-nodejs/db/count';
import { IncomingHttpHeaders } from 'http';
import query from '@dfeidao/atom-nodejs/db/query';
import { systemid, productid } from '../../atom/config';
interface Message {
	filter: {
		sub_process_des: string,
		page_no: number,
		asc?: string[];//升降序
		desc?: string[];
	}
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:e:\Feidao\kh\src\processing-set\zj-000003\s001,action_id:' + action_id);
	const { prepare, exec } = query(action_id, session_id, systemid);
	prepare('hidden_ck_deal_set', ['sub_process_no', 'sub_process_des'], { productid, sub_process_des: { $like: '%' + message.filter.sub_process_des + '%' } }, 2, message.filter.page_no, message.filter.asc || [], message.filter.desc || []);
	const [data] = await exec();

	const { prepare: p, exec: e } = count(action_id, session_id, systemid);
	p('hidden_ck_deal_set', { productid, sub_process_des: { $like: '%' + message.filter.sub_process_des + '%' } });
	const [n] = await e();
	log('Service end path:e:\Feidao\kh\src\processing-set\zj-000003\s001,action_id:' + action_id);
	return {
		data: { data, n }
	};
}
